﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Globalization;

namespace GameUtils
{
    /// <summary>
    /// Floating point rectangle in right-handed coordinate system (Bottom = Y; Top = Y + Height).
    /// </summary>
    public struct RectangleF
    {
        #region Properties
        public float X;
        public float Y;
        public float Width;
        public float Height;

        public float Left
        {
            get { return X; }
        }

        public float Right
        {
            get { return X + Width; }
        }

        public float Top
        {
            get { return Y + Height; }
        }

        public float Bottom
        {
            get { return Y; }
        }

        public Vector2 Center
        {
            get { return new Vector2(X + Width / 2.0f, Y + Height / 2.0f); }
        }

        public Vector2 BottomLeft
        {
            get { return new Vector2(Left, Bottom); }
        }

        public Vector2 BottomRight
        {
            get { return new Vector2(Right, Bottom); }
        }

        public Vector2 TopLeft
        {
            get { return new Vector2(Left, Top); }
        }

        public Vector2 TopRight
        {
            get { return new Vector2(Right, Top); }
        }
        #endregion

        #region Constructors
        public RectangleF(
            float pX,
            float pY,
            float pWidth,
            float pHeight)
        {
            X = pX;
            Y = pY;
            Width = pWidth;
            Height = pHeight;
        }
        #endregion

        #region Methods
        public void Inflate(float pHorz, float pVert)
        {
            X -= pHorz;
            Y -= pVert;
            Width += pHorz * 2.0f;
            Height += pVert * 2.0f;
        }

        public bool Contains(Vector2 pPoint)
        {
            return X <= pPoint.X && pPoint.X <= X + Width && Y <= pPoint.Y && pPoint.Y <= Y + Height;
        }
        #endregion
    }
}